using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using TMPro;
using UnityEngine;

public class UpgradeSelectionArea : MonoBehaviour
{
	public List<UpgradeOption> Options = new List<UpgradeOption>();

	public RectTransform Visuals;

	public GameObject TimerParent;

	public TextMeshProUGUI timerText;

	public GameObject[] StartParents;

	public GameObject UpgradeReminder;

	public List<UpgradeOption> RVOptions = new List<UpgradeOption>();

	private List<UpgradeOption> ShownItems = new List<UpgradeOption>();

	internal void Fill(List<DuelUpgrade> rvUpgrades, List<DuelUpgrade> duelUpgrades, bool showReminder)
	{
		UpgradeReminder.SetActive(showReminder);
		ShownItems = new List<UpgradeOption>();
		foreach (UpgradeOption option in Options)
		{
			option.gameObject.SetActive(value: false);
		}
		foreach (UpgradeOption rVOption in RVOptions)
		{
			rVOption.gameObject.SetActive(value: false);
		}
		for (int i = 0; i < duelUpgrades.Count && i < Options.Count; i++)
		{
			Options[i].Fill(duelUpgrades[i]);
			Options[i].gameObject.SetActive(value: true);
			ShownItems.Add(Options[i]);
		}
		for (int j = 0; j < rvUpgrades.Count && j < Options.Count; j++)
		{
			RVOptions[j].Fill(rvUpgrades[j]);
			RVOptions[j].gameObject.SetActive(value: true);
			ShownItems.Add(RVOptions[j]);
		}
	}

	internal void Hide()
	{
		UpgradeReminder.SetActive(value: false);
		Visuals.DOAnchorPosY(-900f, 0.5f);
		GameObject[] startParents = StartParents;
		for (int i = 0; i < startParents.Length; i++)
		{
			startParents[i].SetActive(value: false);
		}
		StopCoroutine(WaitAndChose());
	}

	internal void Show()
	{
		Visuals.DOAnchorPosY(84f, 0.5f);
		StartCoroutine(WaitAndChose());
	}

	private IEnumerator WaitAndChose()
	{
		yield return new WaitForSeconds(Random.Range(4f, 8f));
		ShownItems.GetRandom().SetAsSelected();
	}

	internal void SetTimer(float popupTimer)
	{
		if (popupTimer > 10f)
		{
			TimerParent.SetActive(value: false);
			return;
		}
		if (popupTimer <= 0f)
		{
			TimerParent.SetActive(value: false);
			return;
		}
		TimerParent.SetActive(value: true);
		timerText.text = Mathf.CeilToInt(popupTimer) + "s";
	}
}
